<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>

<head>
    <title>签约管理</title>
    <style>
        .table-bordered > thead > tr > th{background:#f1f1f1;}
        table.dataTable thead .sorting_disabled{background:#f1f1f1; }
    </style>
</head>

<body>
<style>
    .timeDiv{
        background: #fff;
    }
    .activeDiv{
        background: #ccc;
    }
</style>
<div id="jy wrapper">
    <div class="gray-bg">
        <div class="jy-nav-box">
            <ul class="navbar-nav">
                <%--<li><span>${teamName}</span><a class="switch">切换团队</a></li>--%>
                <li><a href="/medical/base/statistic/listStreet">工作量统计</a></li>
                <li><a href="/medical/base/statistic/listServantStreet">签约服务统计</a></li>
                <li><a href="/medical/base/statistic/listBase"  class="active">基数维护</a></li>
            </ul>
            <%--<span class=""><a href="${ctx}/medical/base/statistic/edit?" class="btn-primary btn-add "> <i class='fa fa-plus-square-o'></i> 新 增</a></span>--%>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox">
                        <div class="ibox-content">
                            <div class="search-area">
                                <form role="form" class="form-inline" id="queryform">
                                    <input type="hidden" id="year" name="year"  class="form-control form-filter">
                                    <input type="hidden" id="month" name="month"  class="form-control form-filter">
                                    <%--<input type="hidden" id="year" name="year" value="${year}" class="form-control form-filter">
                                    <input type="hidden" id="month" name="month" value="${month}" class="form-control form-filter">--%>
                                    <%--<div class="leftTit" style="width:12%;line-height: 40px;height: 40px;float: left;margin-bottom: 10px;background-color: #fff;margin-right: 3%;">
                                        <span style="display: block;width: 4px;height: 20px;background: #26a69a;float: left;margin: 10px;"></span>
                                        <span>统计时间列表</span>
                                    </div>--%>
                                    <%--<div class="rightTit" style="width:84%;line-height: 40px;height: 40px;float: left;margin-bottom: 10px;background-color: #fff;">
                                        <span style="display: block;width: 4px;height: 20px;background: #26a69a;float: left;margin: 10px;"></span>
                                        <span>统计</span>
                                    </div>--%>
                                    <div id="time_select" style="width: 15%; float: left;"></div>
                                    <button class="btn" type="button" onclick="add()">  新 增</button>
                                </form>

                            </div>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover dataTables" id="data-table"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>

<script src="${ctx}/static/inspinia/js/plugins/layer/layer.js"></script>
<!-- Page-Level Scripts -->
<script>
    "use strict";

    var setting = {
        searching:false, //去掉搜索框
        bLengthChange:false,//去掉每页多少条框体
        destroy:true, //Cannot reinitialise DataTable,解决重新加载表格内容问题
        "ajax": {
            "url": "${ctx}/medical/base/statistic/listBase",
            "type": "POST"
        },
        "columns": [
            {"title": "", "data": "region", "width": "4%", "orderable": false},
            {"title": "辖区常住人口数", "data": "czrks", "width": "5%", "orderable": false},
            {"title": "非重点人群", "data": "typeFzd", "width": "5%", "orderable": false},
            {"title": "辖区重点人群", "data": "keyGroup", "width": "5%", "orderable": false},
            {"title": "0-6岁儿童", "data": "typeEt", "width": "4%", "orderable": false},
            {"title": "孕产妇", "data": "typeYcf", "width": "5%", "orderable": false},
            {"title": "65岁以上老年人", "data": "typeLnr", "width": "5%", "orderable": false},
            {"title": "高血压患者", "data": "typeGxy", "width": "5%", "orderable": false},
            {"title": "2型糖尿病患者", "data": "typeTnb", "width": "5%", "orderable": false},
            {"title": "重性精神疾病患者", "data": "typeJsb", "width": "5%", "orderable": false},
            {"title": "肺结核患者", "data": "typeFjh", "width": "5%", "orderable": false},
            {"title": "农村建档立卡低收入人口", "data": "typeDsr", "width": "5%", "orderable": false},
            {"title": "城镇低保人群", "data": "typeCzdb", "width": "5%", "orderable": false},
            {"title": "计划生育特殊家庭", "data": "typeTs", "width": "5%", "orderable": false},
            {"title": "残疾人", "data": "typeCjr", "width": "5%", "orderable": false},
            {"title": "操作", "data": null, "width": "5%", "orderable": false},
        ],
        "columnDefs": [
            {
             "targets": 15,
             "render": function (data, type, row, meta) {
             var year = $('#year').val(), month = $('#month').val();
             var url = '${ctx}/medical/base/statistic/edit?regionId='
             + row.regionId + '&year=' + year + '&month=' + month;
             var up = "<a class='btn btn-xs default btn-editable' href='" + url + "'><i class='fa fa-pencil-square-o'></i> 编辑 </a>";
             return up;
             },
             "orderable": false
             }
        ]
    };

    $.post('/medical/base/statistic/findTimes', {}, function(data){
        if (data && data.timeList) {
            buildTimeHtml(data.timeList);
        }
    }, "json");


    function buildTimeHtml(timeList) {
        var html = '';
        for (var i = 0; i < timeList.length; i++) {
            var v = timeList[i];
            var arr = v.split('-');
            html += '<div class="timeDiv" style="line-height: 35px;cursor:pointer;height: 35px;margin-right: 40px;" onclick="clickEvent(this, \''+ arr[0] +'\', \''+ arr[1] +'\');">'
            + arr[0] + '年' +  arr[1] + '月</div>';
        }
        $('#time_select').html(html);

        var item = timeList[0];
        var array = item.split('-');
        setYearMonth(array[0], array[1]);
        $('.timeDiv').eq(0).addClass("activeDiv");
        $('#data-table').DataTable(ehconfig.get_datatable_config(setting));
    }

    function setYearMonth(year, month) {
        $('#year').val(year);
        $('#month').val(month);
    }

    function add() {
        location.href="${ctx}/medical/base/statistic/edit?"
    }

    function clickEvent(obj, year, month) {
        setYearMonth(year, month);
        console.log(year);
        console.log(month);
        $('.timeDiv').removeClass("activeDiv");
        $(obj).addClass("activeDiv");
        $('#data-table').DataTable(ehconfig.get_datatable_config(setting));
    }

</script>

</body>

</html>
